package com.juc.locks;

import com.ha7419x.service.Test;

import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TestLocks extends Thread {

    static Lock lock=new ReentrantLock();

    private static String abs = new Random().toString();

    @Override
    public void run() {
        lock.lock();
        System.out.println(lock);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + ":" + abs);
        lock.unlock();
    }

    public static void main(String[] args) {
        TestLocks testLocks1 = new TestLocks();
        testLocks1.start();
        TestLocks testLocks2 = new TestLocks();
        testLocks2.start();
    }
}
